/**
 * 签到页面
 * author:yinht
 * date:2017年6月2日19:30:42
 */
;
define(function(require, exports, module) {
	var wechat = require("wechat");

	var search = {
		/**
		 * bindEvent 页面事件
		 */
		type:"",
		bindEvent: function() {
			//返回
			$("#return_search").unbind().on("click", function() {
				window.history.back(-1);
			});
			
			/*document.getElementById("searchSubmit").onsubmit = function () {
				
			}*/
			$("#keyword").on('keypress',function(e) {  
                var keycode = e.keyCode;  
                var key = $(this).val();
                sessionStorage.setItem("key",key);
                if(keycode=='13') {  
                    e.preventDefault();    
                    //请求搜索接口  
                    search.sendParam();
                }  
         });
		},
		/**
		 * 进行页面路由监听配置
		 * 
		 */
		bindRout: function() {
			//公共页面监听路由
			Path.map("#home").to(function() {
				//返回首页
				common.loadPage({
					pageUrl: "html/index.html",
					reload: true,
					from: "left"
				});
			});
			Path.map("#/index/:page_name").to(function() {
				console.log(this.params["page_name"]);
				var page_name = this.params["page_name"];
				var nextPageFrom = "left"; //从右边过来
				//记录状态
				common.loadPage({
					pageUrl: "html/" + page_name + ".html",
					reload: true,
					from: nextPageFrom
				});
			});
			Path.listen();
		},

		/**
		 * 页面数据加载
		 */
		sendParam:function(){
			var pk_user = localStorage.getItem("pk_user");
			var key = sessionStorage.getItem(key);
			console.log(key);
			var param = {
					"pk_user":pk_user,
					"key":key
					}
			common.loadData({
				url: "/wxmember/service/search", //"/UMPPubServlet?method=getWxUserInfo",
				param: param,
				successCallBack: search.searchCallBack, //回调函数
				dataSource: "search",
				cache: false
			});
		},
		loadData: function() {
			//接口数据
			
		},
		searchCallBack: function(json) {
			console.log(JSON.stringify(json));
			if(json.status == "0") {
				var html="";
				for(var i=0;i<json.data.list.length;i++){
					html +=" <div id='p_pend' class='men_mana pending public'>"
						+" <a href='#/index/men_details'>"
						+"<div class='sp_img lf'>"
						+"	<img src='images/energy.png' alt=''>"
						+"  </div>"	
						+" <div class='sp_item rf'>"	
						+"		<div class='h_top'>"
						+"			<span class='lf'><b>"+json.data.list[i].name+"</b>-<b>"+json.data.list[i].currentLevel+"</b></span>"
						+"			<span class='rf mana_time'>"+json.data.list[i].createTime+"</span>"
						+"		</div>"
						+"		<div class='h_bottom'>"
						+"			<span class='lf'><b>对接人</b> : <b>"+json.data.list[i].docker+"</b></span>"
						+"			<span class='rf tel'>打电话</span>"
						+"		</div>"
						+"	</div>"
						+"	</a>"
						+"	</div>";
					$("#serach_members").html(html);
				}
			}
			common.initIscroll({
				container: "iscrollContent_searchlist",
				showScrollBar: false,
				index: 1
			});
		},
			
		/**
		 * each page init mothed
		 */
		initialize: function() {

			this.loadData();
			//事件绑定
			this.bindEvent();
			//路由绑定
			this.bindRout();
		}
	};

	module.exports = search;
});

